home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 17784 / parttext-x-pgp0 < prev   
Encoding:
PGP Message  |  1996-08-05  |  1.6 KB  |  58 lines

  1. -----BEGIN PGP SIGNED MESSAGE-----
  2.  
  3. >>>>> In article <3174c0dc.7652220@news.flex.com.au>,
  4. >>>>> Tony == "Tony L" <cobweb@flex.com.au> writes:
  5.  
  6. Tony> I have come across two different ways that 2 different beginners
  7. Tony> books recommend that every program should start.  Could someone
  8. Tony> please tell me which one is the "BEST" or proper way?
  9.  
  10. Tony> #include <stdio.h>
  11. Tony> void main()
  12. Tony> {
  13. Tony>     printf("Hello!\n");
  14. Tony>     return 0;
  15. Tony> }
  16.  
  17. This is definitely wrong, and your compiler should complain about
  18. this.  You have said that the function doesn't return a value, then
  19. you try to return zero.
  20.  
  21.  
  22. Tony> Or, the same as above but not include "void":
  23.  
  24. Tony> #include <stdio.h>
  25. Tony> main()
  26. Tony> {
  27. Tony>     printf("Hello!\n");
  28. Tony>     return 0;
  29. Tony> }
  30.  
  31. In this case, the compiler assumes "int main()" which is consistent
  32. with the return, so no error there.
  33.  
  34. The two portable declarations for main() are "int main()" and "int
  35. main(int, char**)"; make sure you do return an integer!  Some
  36. environments may accept other forms (for example "void main()"), but I
  37. don't recommend this for portable code.
  38.  
  39. More info is in the FAQ.
  40.  
  41.  
  42. Tony> As I am just really starting out in "C", I'd like to get off to
  43. Tony> the right way.  :-)
  44.  
  45. Then perhaps you should have posted in comp.lang.c  ;-)
  46. ^L
  47.  
  48. -----BEGIN PGP SIGNATURE-----
  49. Version: 2.6.3i
  50. Charset: noconv
  51. Comment: Processed by Mailcrypt 3.4, an Emacs/PGP interface
  52.  
  53. iQB1AwUBMXUA3edsuUurvcRtAQEyWQL/fsHHEh8nHWnXCvBocohn3xdn9ax8ClMl
  54. xi75oqFFU077b679KU1CmYp5EYZgXbi03jgDuzPQO88fxoTZo1AIZumpND58fY5U
  55. hF3nxAJIxZq2bQZ3B4Bw8sp8AWJqzb9i
  56. =4MPP
  57. -----END PGP SIGNATURE-----
  58.